package dao;


import java.sql.*;

//驼峰命名
public class ProductDaoImpl {

    public static void main(String[] args) {
        show();
    }


    // 方法
    public static void show() {

        // jdbc
        // 1、加载驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");

            //2、获取连接
            String url = "jdbc:mysql://localhost:3306/yggl?useUnicode=true&characterEncoding=utf8";
            String user = "root";
            String pass = "root";
            Connection connection = DriverManager.getConnection(url, user, pass);
            // ctrl+/  注释代码
//            if (connection != null) {
//                System.out.println("连接成功");
//            }
            // 3、创建sql语句
            String sql = "select * from employees ";

            // 4、预编译sql
            PreparedStatement preparedStatement = connection.prepareStatement(sql);

            // 5、执行sql
            ResultSet resultSet = preparedStatement.executeQuery();

            // 6、遍历结果
            while (resultSet.next()){
                // ctrl+d 复制一行
                String id = (String) resultSet.getObject(1);
                String name = (String) resultSet.getObject(2);
                String xueli = (String) resultSet.getObject(3);
                System.out.println(id+"---"+name+"---"+xueli);
            }

        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
